import diff from "../diff"

export default function updateComponent(virtualDOM, oldComponent, oldEl, container) {
    oldComponent.componentWillReceiveProps()
    if (oldComponent.shouldComponentUpdate(virtualDOM.props)) {
        let prevProps = oldComponent.props
        oldComponent.componentWillUpdate(virtualDOM.props)
        // 组件更新
        oldComponent.updateProps(virtualDOM.props)
        const newVirtualDOM = oldComponent.render()
        newVirtualDOM.component = oldComponent
        diff(newVirtualDOM, container, oldEl)
        oldComponent.componentDidUpdate(prevProps)
    }
}